import { reactive, toRaw, ToRefs, toRefs } from "vue";
import ComponentController, { GetMethods, GetState } from '@/common/controller';
import TableMixins from '@/common/tableMixins';
import DashboardApi from "@/api/dashboard"
import { DashboardSaleData,DashboardSaleDataQuery} from "@/api/dashboard/types";

class Controller extends TableMixins<DashboardSaleData> implements ComponentController {
	/**页面的模型数据 */
	state: {
		table:Table.Map<DashboardSaleData,DashboardSaleDataQuery>
	};
	/**首页的控制器 */
	constructor(){
		//继承父类并注入表格的api
		super({api:DashboardApi.getIndexSaleList})
		//定义state 类似2.0的data
		this.state=reactive({
			table: this.table,
		})
		this.state.table.query={
			shop_name:"",
			date:[],
		}
	}
	/**导出state */
	getState() {
		return {
			...toRefs(this.state),
		}
	}
	/**导出methods */
	getMethods() {
		return {
			onSearch:this.onSearch.bind(this),
			resetQuery:this.resetQuery.bind(this),
			pageChange:this.pageChange.bind(this),
			sizeChange:this.sizeChange.bind(this),
		}
	}

	private onSearch(){
		this.getTableData()
	}

}

export default Controller
